package java7;

import java.io.IOException;
import java.sql.SQLException;

/**
 * @author lwx
 * @desc  https://blog.csdn.net/min996358312/article/details/65729617
 * @create 2018-06-21 17:13
 */
public class ExcepitonTest {


    public static void main(String[] args) {

        try {
            test();
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (IOException throwable) {
            throwable.printStackTrace();
        }

        //JDK7的做法，主要是避免多个catch
        try {
            test();
        } catch (SQLException | IOException e) {
            e.printStackTrace();
        }


    }

    public static void test() throws SQLException, IOException {
        System.out.println("测试JDK7中的多异常捕获");

    }

    //public void rethrowException(String exceptionName) throws Exception {//JDK6用法
    public void rethrowException(String exceptionName) throws SQLException,IOException, MyExcepiton {
        /*
        * try子句会抛出该异常。
在此之前，没有其他的catch子句捕获该异常。
该异常类型是catch子句捕获的多个异常中的一个异常类型的父类或子类。
https://blog.csdn.net/aqzwss/article/details/46354125
        * */
        try {
            if (exceptionName.equals("First")) {
                throw new SQLException();

            } else if(exceptionName.contains("xx")) {
                throw new IOException();
            }
            rethrowException2(exceptionName);
        } catch (Exception e) {
          //  e=new Exception();
            throw e;

        }
    }

    public void rethrowException2(String exceptionName) throws MyExcepiton {
        throw new MyExcepiton();
    }



    class MyExcepiton  extends Exception{


    }

}



